package com.ruoyi.web.controller.customer;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.team.domain.CustomerVisitDemo;
import com.ruoyi.team.service.ICustomerVisitDemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 拜访记录Controller
 *
 * @author lijiayang
 * @date 2022-11-27
 */
@RestController
@RequestMapping("/customer/visit")
public class CustomerVisitDemoController extends BaseController
{
    @Autowired
    private ICustomerVisitDemoService customerVisitDemoService;

    /**
     * 查询拜访记录列表
     */
    @PreAuthorize("@ss.hasPermi('customer:visit:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerVisitDemo customerVisitDemo)
    {
        startPage();
        List<CustomerVisitDemo> list = customerVisitDemoService.selectCustomerVisitDemoList(customerVisitDemo);
        return getDataTable(list);
    }

    /**
     * 导出拜访记录列表
     */
    @PreAuthorize("@ss.hasPermi('customer:visit:export')")
    @Log(title = "拜访记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerVisitDemo customerVisitDemo)
    {
        List<CustomerVisitDemo> list = customerVisitDemoService.selectCustomerVisitDemoList(customerVisitDemo);
        ExcelUtil<CustomerVisitDemo> util = new ExcelUtil<CustomerVisitDemo>(CustomerVisitDemo.class);
        util.exportExcel(response, list, "拜访记录数据");
    }

    /**
     * 获取拜访记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('customer:visit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(customerVisitDemoService.getById(id));
    }

    /**
     * 新增拜访记录
     */
    @PreAuthorize("@ss.hasPermi('customer:visit:add')")
    @Log(title = "拜访记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerVisitDemo customerVisitDemo)
    {
        return toAjax(customerVisitDemoService.save(customerVisitDemo));
    }
}
